package com.teyao.teyao_back.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teyao.teyao_back.config.myPage;
import com.teyao.teyao_back.entity.ProductViewWrapper;
import com.teyao.teyao_back.mapper.ProductViewMapper;
import com.teyao.teyao_back.service.ProductViewService;
import org.springframework.stereotype.Service;

@Service
public class ProductViewServiceImpl extends ServiceImpl<ProductViewMapper, ProductViewWrapper> implements ProductViewService {

    //不定查询
    @Override
    public myPage MyQuery(Integer currentPage, Integer size, ProductViewWrapper product) {
        QueryWrapper<ProductViewWrapper> queryWrapper = new QueryWrapper<>();
        if (product.getNickName() != null && !product.getNickName().isBlank()) {
            queryWrapper.like("nick_name", product.getNickName().trim());
        }
        if (product.getProductName() != null && !product.getProductName().isBlank()) {
            queryWrapper.like("product_name", product.getProductName().trim());
        }
        if (product.getSuppliers() != null && !product.getSuppliers().isBlank()) {
            queryWrapper.like("suppliers", product.getSuppliers().trim());
        }
        if (product.getClasss() != null && !product.getClasss().isBlank()) {
            queryWrapper.eq("classs", product.getClasss());
        }
        if (product.getType() != null && !product.getType().isBlank()) {
            queryWrapper.eq("type", product.getType());
        }
        myPage myPage = new myPage();
        myPage.setCurrentPage(currentPage);
        Page<ProductViewWrapper> page = new Page(myPage.getCurrentPage(), size);
        IPage result = baseMapper.selectPage(page, queryWrapper);
        myPage.setTotal((int) result.getTotal());
        myPage.setData(result.getRecords());
        return myPage;
    }
}
